home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- organization: Eindhoven University of Technology, The Netherlands
- subject: v08i014: line wrapper for BIT/EARNnet mailings
- From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Reply-To: wsinrobg@urc.tue.nl (Rob Gerth)
-
- Posting-number: Volume 8, Issue 14
- Submitted-by: wsinrobg@urc.tue.nl (Rob Gerth)
- Archive-name: wrap
-
- IBM is still firmly committed to Holerith cards as BIT/EARNnet users can
- testify. Here is a shell script that wraps long lines in a file so that
- they can be reconstituted by piping thru sh---see the comments in the script.
-
- This script uses sed and has been tested on SUNs and ULTRIX vaxen. The
- ULTRIX sed is buggy, so I had to rewrite the wrap script. The original
- unwrap script worked on both systems. In other words: there may be surprises.
- Enjoy,
- # Rob Gerth #
- # #
- # uucp: wsinrobg@eutrc3.urc.tue.nl | Eindhoven University of Technology #
- # bitnet: wsdcrobg@heitue5 | 5600 MB Eindhoven, The Netherlands #
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: wrap
- # Wrapped by wsinrobg@eutrc3 on Thu Aug 24 18:11:49 1989
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'wrap' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'wrap'\"
- else
- echo shar: Extracting \"'wrap'\" \(2087 characters\)
- sed "s/^X//" >'wrap' <<'END_OF_FILE'
- X: !/bin/sh
- X# NAME
- X# wrap
- X# SYNOPSIS
- X# wrap [-nnn] [-s] [file]
- X# DESCRIPTION
- X# Wrap wraps lines to nnn chars (default 80): BITNET does not like
- X# lines longer than that.
- X# It reads file (standard input if no file is specified) and
- X# writes lines of specified maximal length to standard output,
- X# embedded in a shell script running of which restores the original.
- X# If file is specified, wrap checks if it is a shar file (by searching
- X# for the string "# This is a shell archive" at the start of a line)
- X# and, if so, adapts the surrounding shell script appropriately.
- X# Specifying -s makes wrap behave as if it were wrapping a shar file
- X# without checking.
- X# Recommended use: shar foo ... | wrap -s >bar
- X# to be restored with sh bar
- X# VERSION
- X# 1.1
- X# BUGS
- X# This should of course be an option of shar.
- X# AUTHOR
- X# Rob Gerth, Eindhoven University of Technology
- X# wsinrobg@eutrc3.urc.tue.nl or WSDCROBG@HEITUE5.BITNET
- X#
- X#
- XFILE=
- XSHAR=
- XDEFAULT=79
- XLEN=$DEFAULT
- XLINE=
- XCL="+"
- XLL="-"
- X
- Xfor i
- Xdo
- X case $i in
- X -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9]) LEN=`expr $i : '-\(.*\)'`;;
- X -s) SHAR=1;;
- X -*) echo "Usage: wrap [-nnn] [-s] [file]" 1>&2; exit 1;;
- X *) FILE="$i"; break;;
- X esac
- Xdone
- X
- Xtest \( -z "$SHAR" \) -a \( -n "$FILE" \) &&
- X SHAR=`egrep '^# This is a shell archive' $FILE`
- X
- Xif test $LEN -eq 0
- Xthen echo "Linelength ($LEN) set to default: `expr $DEFAULT + 1`" 1>&2;
- X LEN=$DEFAULT
- Xfi
- X
- XLINE=`yes | sed "
- X H
- X $LEN { g
- X s/\\n//g
- X y/y/./
- X q
- X }
- X d" 2>/dev/null`
- X
- Xcat <<\EOF
- X: !/bin/sh
- X# Remove everything before the previous line and pipe through sh.
- X#
- XEOF
- Xif test "$SHAR"
- Xthen echo "{ sed '"
- Xelse echo "sed '"
- Xfi
- Xcat <<EOF
- X s/^$LL//
- X x
- X t last
- X /^$CL/ {
- X x
- X s/^$CL//
- X H
- X }
- X d
- X : last
- X /^$CL/ {
- X x
- X H
- X s/^.*$//
- X }
- X x
- X s/^$CL//
- X s/\n//g
- X' <<"EOF_CUT"
- XEOF
- X#
- X# ULTRIX sed has buggy code for the t function
- X#
- X#sed "
- X# : start
- X# h
- X# s/^\($LINE\)..*/$CL\1/p
- X# t large
- X# s/^/$LL/
- X# b
- X# : large
- X# g
- X# s/^$LINE//
- X# t start
- X#" $FILE
- X#
- Xsed "
- X : start
- X h
- X s/^\($LINE\)..*/$CL\1/p
- X /^$CL$LINE/ !{
- X s/^/$LL/
- X b
- X }
- X g
- X s/^$LINE//
- X b start
- X" $FILE
- Xecho EOF_CUT
- Xtest "$SHAR" && echo '} | sh'
- END_OF_FILE
- if test 2087 -ne `wc -c <'wrap'`; then
- echo shar: \"'wrap'\" unpacked with wrong size!
- fi
- chmod +x 'wrap'
- # end of 'wrap'
- fi
- echo shar: End of shell archive.
- exit 0
-
-